package main

import (
	"fmt"
)

func main() {
	node1 := &Node{val: 1}
	node2 := &Node{val: 2}
	node3 := &Node{val: 3}
	node1.next = node2
	node2.next = node3
	traversedNode := traversal(node1)
	for traversedNode != nil {
		fmt.Println(traversedNode.val)
		traversedNode = traversedNode.next
	}
	fmt.Println()
}

// traversal 翻转单向链表
func traversal(currentNode *Node) *Node {
	var prevNode *Node
	for currentNode != nil {
		nextNode := currentNode.next
		currentNode.next = prevNode
		prevNode = currentNode
		currentNode = nextNode
	}
	return prevNode
}
